import axios from "axios";

const { createSlice } = require("@reduxjs/toolkit");

const billStore = createSlice({
    name: "bill",
    initialState: {
        billList: []
    },
    reducers: {
        setBillList(state, action) {
            state.billList = action.payload
        }
    }
})

const { setBillList } = billStore.actions;

const getBillList = () => {
    return async (dispatch) => {
        const res = await axios.get("http://localhost:8000/bill");
        dispatch(setBillList(res.data))
    }
}

const reducer = billStore.reducer;

export { getBillList };
export default reducer;